//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
namespace LargoCommon.Midi
{
using System;
using System.Globalization;
using System.IO;
using System.Text;
using Music;
/// MIDI event to apply pressure to a channel's currently playing notes.
[Serializable]
public sealed class VoiceChannelPressure : VoiceEvent {
#region Fields
/// The category status byte for ChannelPressure messages.
private const byte CategoryStatusByte = 0xD;
/// The amount of pressure to be applied (0x0 to 0x7F).
private byte pressure;
#endregion
#region Constructors
/// Initializes a new instance of the VoiceChannelPressure class.
/// The delta-time since the previous message.
/// The channel to which to write the message (0 through 15).
/// The pressure to be applied.
public VoiceChannelPressure(long deltaTime, MidiChannel channel, byte givenPressure) :
base(deltaTime, CategoryStatusByte, channel) {
this.Pressure = givenPressure;
}
#endregion
#region Properties
/// Gets The first parameter as sent in the MIDI message.
/// General musical property.
public override byte Parameter1 => this.pressure;
/// Gets The second parameter as sent in the MIDI message.
/// General musical property.
public override byte Parameter2 => 0;
/// Gets or sets the amount pressure to be applied (0x0 to 0x7F).
/// General musical property.
private byte Pressure {
get => this.pressure;
set {
if (value > 127) {
this.pressure = 127;
return;
//// throw new ArgumentOutOfRangeException("value", value, "The pressure must be in the range from 0 to 127.");
}
this.pressure = value;
}
}
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
sb.Append("\t");
sb.Append("0x");
sb.Append(this.Pressure.ToString("X2", CultureInfo.CurrentCulture.NumberFormat));
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
// Write out the data
outputStream.WriteByte(this.pressure);
}
#endregion
}
}